#include"comm.hpp"

int main()
{
    int ret = mkfifo(FIFO_FILE, MODE); // 命名管道创建
    if(ret < 0)
    {
        perror("mkfifo");
        exit(FIFO_CREATE_ERR);
    }

    cout << "client make file done" << endl;

    int fd = open(FIFO_FILE, O_WRONLY);
    if(fd < 0)
    {
        perror("open");
        exit(FIFO_OPEN_ERR);
    }

    cout << "client open file done" << endl;

    string line;
    while(1)
    {
        cout << "please enter# ";
        getline(cin, line);
        if(line == "exit")
        {
            cout << "message over, exit." << endl;
            break;
        }
        write(fd, line.c_str(), line.size());
    }

    close(fd);

    unlink(FIFO_FILE);
    return 0;
}